package com.ecs.to_tos_service.controller;

/**
 * Created by wawayang on 2019/4/11.
 */

import com.ecs.to_tos_service.domain.Product;
import com.ecs.to_tos_service.service.ProductService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;


@RestController
@RequestMapping("/api/v1/product")
public class ProductController {

    @Autowired
    private ProductService productService;

    @Value("${server.port}")
    private String port;

    @RequestMapping("list")
    public Object list(){
        return productService.listProduct();
    }

    @RequestMapping("find")
    public Object findByid(@RequestParam("id") int id) throws InterruptedException {
        if (1== id)
        {

//            Thread.sleep(100000);
            TimeUnit.SECONDS.sleep(2);
        }
        Product product = productService.findById(id);
        Product result = new Product();
        BeanUtils.copyProperties(product,result);

        result.setName( result.getName() + "data from port = " + port);

        return result ;
    }

}
